﻿$(document).ready(function () {

    $("#add-activity").on("click", function () {
        location.href = "/Meeting/Create"
    });

    $(function () {
        $("#flash-messages").flashMessage({ timeout: 5000}); // .flashMessage() = default som är 3000(ms).
    });

    $("#radioButtonMeeting input").prop('checked', true); // Sätter radiobutton för Meeting att vara checked direkt.



    $("#radioButtonMeeting input").on("click", function () { // Click event för radiobutton att visa dropdownen.

        $("#usersContacts").show();

    });

    $("#radioButtonTask input").on("click", function () {

        $("#usersContacts").hide();
    });

    /// DATETIME PICKER
    $('#StartTime').datetimepicker();
    $("#EndTime").datetimepicker();

    //
    // ADD RECEIVERS TO MEETING
    //
    //

    $("#addReceiver").on("click", function () {
        var receiverValue = $("#Receivers option:selected").val();
        var exist = 0 == $("#SelectedReceivers option[value=" + receiverValue + "]").length;
        if (exist) {
            var receiverText = $("#Receivers option:selected").text();
            var htmlString = "<option value=" + receiverValue + ">" + receiverText + "</option>";
            $("#SelectedReceivers").append(htmlString);
        }
        $("#Selected").val("");
        $("#SelectedReceivers option").each(function () {
            $("#Selected").val($("#Selected").val() + "," + $(this).val());
        });
    });

    $("#deleteReceiver").on("click", function () {
        $("#SelectedReceivers option:selected").remove();
        $("#Selected").val("");
        $("#SelectedReceivers option").each(function () {
            $("#Selected").val($("#Selected").val() + "," + $(this).val());
        });
    });

    //
    // ADD CONTACTS TO MEETING
    //
    //

    $("#addContact").on("click", function () {
        var contactValue = $("#Contacts option:selected").val();
        var exist = 0 == $("#SelectedContactList option[value=" + contactValue + "]").length;
        if (exist) {
            var contactText = $("#Contacts option:selected").text();
            var htmlString = "<option value=" + contactValue + ">" + contactText + "</option>";
            $("#SelectedContactList").append(htmlString);
        }
        $("#SelectedContacts").val("");
        $("#SelectedContactList option").each(function () {
            $("#SelectedContacts").val($("#SelectedContacts").val() + "," + $(this).val());
        });
    });

    $("#deleteContact").on("click", function () {
        $("#SelectedContactList option:selected").remove();
        $("#SelectedContacts").val("");
        $("#SelectedContactList option").each(function () {
            $("#SelectedContacts").val($("#SelectedContacts").val() + "," + $(this).val());
        });
    });

    ///
    /// CALENDAR
    ///

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();


    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        editable: false,
        events: "/Calendar/GetEvents/",
        timeFormat: 'H:mm{ - H:mm}'
    });


});